from bs4 import BeautifulSoup
import requests
import lxml
import bs4

url = "http://localhost/shopxo/"
try:
    response = requests.get(url)
except:
    raise Exception('请求失败')

html_content = response.text
soup = BeautifulSoup(html_content,'lxml')

# print(f'soup类型：{type(soup)}')
# print(f'title：{soup.title}')
# print(f'tile 类型：{type(soup.title)}')
# print(soup.title.string) # 输出标签内的数据
# print(f'soup.title.string 类型:{type(soup.title.string)}')
# print(soup.a.string)

# 获取页面顶部em标签,获取兄弟节点
# print(soup.em)
# print(repr(soup.em.next_sibling))
# print(soup.em.next_sibling.next_sibling)

# 获取em标签的父节点
# print(soup.em.parent.parent.parent)
# print(soup.em.parents)
# for item in soup.em.parents:
#     print(item)
#     print()

# find方法
# nav = soup.find('ul',{'class':'top-nav-right'})
# # print(nav)
# for item in nav.children:
#     # print(repr(item))
#     if item != '\n':
#         print(item.span.string)

# find_all方法
# nav = soup.find_all('',{'class':'top-nav-items'})
# for item in nav:
#     if item.span:
#         print(item.span.string)

# select 方法
nav = soup.select('.top-nav-items .login-event')
for item in nav:
    print(item.span.string)